﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Collections.ObjectModel;

namespace XMM.Dialoges
{
    /// <summary>
    /// Interaktionslogik für ManageAudiences.xaml
    /// </summary>
    public partial class ManageAudiences : Window
    {
        ObservableCollection<Objects.Audition> Auditions
        { get { return _Auditions; } }

        ObservableCollection<Objects.Audition> _Auditions = new ObservableCollection<Objects.Audition>();

        XMM.Library ParentMainWindow;

        public ManageAudiences(XMM.Library dlgParentMainWindow)
        {
            InitializeComponent();

            ParentMainWindow = dlgParentMainWindow;
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            loadAudiences();
        }

        public void loadAudiences()
        {
            _Auditions = new ObservableCollection<Objects.Audition>();

            List<Objects.Audition> lAudiences = Objects.Audition.getAllAuditions();

            foreach (Objects.Audition oAudience in lAudiences)
            {
                _Auditions.Add(oAudience);
            }

            lvAudiences.ItemsSource = Auditions;
            lvAudiences.Items.Refresh();
        }

        private void btnExit_Click(object sender, RoutedEventArgs e)
        {
            ParentMainWindow.RefreshXMM();
            Close();
        }

        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            AddAudience dlgAddAudience = new AddAudience(this);
            dlgAddAudience.ShowDialog();
        }

        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            if (lvAudiences.SelectedIndex > -1)
            {
                if (Objects.Audition.Delete(((Objects.Audition)lvAudiences.SelectedItem).AuditionID))
                    loadAudiences();
            }
            else
            {
                MessageBox.Show("Bitte wählen Sie zuerst einen Zuseher-Eintrag aus!", "Kein Zuseher gewählt", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
        }
    }
}
